package com.example.xuyuli.controller;

import com.example.xuyuli.HelloServlet;
import com.example.xuyuli.entity.User;
import com.example.xuyuli.repository.impl.UserRepositoryimpl;
import com.example.xuyuli.service.impl.LoginServiceimpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
@WebServlet("/login")
public class LoginServlet extends HelloServlet {
    int acount = 0;

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String name = req.getParameter("name");
        String password = req.getParameter("password");
        System.out.println(name);
        LoginServiceimpl loginServiceimpl = new LoginServiceimpl();
        User user = loginServiceimpl.login(name, password);

        if (user!=null){
            HttpSession session=req.getSession();
            session.setAttribute("name",name);
            resp.sendRedirect("LoginSuccess.jsp");
        }else {
            resp.sendRedirect("Login.jsp");
        }

    }



}
